home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Resources / Online / Term / Extras / Source / term-source.lha / Rendezvous.c < prev    next >
C/C++ Source or Header  |  1996-10-20  |  4KB  |  178 lines

  1. /*
  2. **    Rendezvous.c
  3. **
  4. **    External program interface for Amiga telecommunications software
  5. **
  6. **    Copyright © 1990-1996 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #ifndef _GLOBAL_H
  13. #include "Global.h"
  14. #endif
  15.  
  16.     /* TaskDestructor(struct DataMsg *Item):
  17.      *
  18.      *    Msg destructor for the routines below.
  19.      */
  20.  
  21. STATIC VOID
  22. TaskDestructor(struct DataMsg *Item)
  23. {
  24.     Signal((struct Task *)Item->Data,SIGBREAKF_CTRL_F);
  25. }
  26.  
  27. struct RendezvousData * SAVE_DS ASM
  28. RendezvousLogin(REG(a0) struct MsgPort *ReadPort,REG(a1) struct MsgPort *WritePort,REG(a2) struct TagItem *UnusedTagList)
  29. {
  30.     struct RendezvousData *Data;
  31.  
  32.     if(Data = (struct RendezvousData *)AllocVecPooled(sizeof(struct RendezvousData),MEMF_ANY | MEMF_CLEAR))
  33.     {
  34.         struct DataMsg Msg;
  35.  
  36.         InitMsgItem(&Msg,(DESTRUCTOR)TaskDestructor);
  37.  
  38.         Msg.Type = DATAMSGTYPE_RENDEZVOUS;
  39.         Msg.Data = (UBYTE *)FindTask(NULL);
  40.  
  41.         Forbid();
  42.  
  43.         ClrSignal(SIGBREAKF_CTRL_F);
  44.  
  45.         PutMsgItem(SpecialQueue,(struct MsgItem *)&Msg);
  46.  
  47.         Wait(SIGBREAKF_CTRL_F);
  48.  
  49.         Permit();
  50.  
  51.         if(ReadRequest && WriteRequest)
  52.         {
  53.             struct Node *Node;
  54.  
  55.             CopyMem(ReadRequest,&Data->rd_ReadRequest,sizeof(struct IOExtSer));
  56.  
  57.             Data->rd_ReadRequest.IOSer.io_Message.mn_ReplyPort = ReadPort;
  58.  
  59.             CopyMem(WriteRequest,&Data->rd_WriteRequest,sizeof(struct IOExtSer));
  60.  
  61.             Data->rd_WriteRequest.IOSer.io_Message.mn_ReplyPort = WritePort;
  62.  
  63.             if(Window)
  64.                 Data->rd_Screen = Window->WScreen;
  65.  
  66.             NewList(&Data->rd_UploadList);
  67.             NewList(&Data->rd_DownloadList);
  68.             NewList(&Data->rd_SentList);
  69.             NewList(&Data->rd_ReceivedList);
  70.  
  71.             while(Node = RemoveFirstGenericListNode(GenericListTable[GLIST_UPLOAD]))
  72.                 AddTail(&Data->rd_UploadList,Node);
  73.  
  74.             Data->rd_SendPath        = Config->PathConfig->BinaryUploadPath;
  75.             Data->rd_ReceivePath    = Config->PathConfig->BinaryDownloadPath;
  76.             Data->rd_Options        = "";
  77.         }
  78.         else
  79.         {
  80.             FreeVecPooled(Data);
  81.  
  82.             Data = NULL;
  83.         }
  84.     }
  85.  
  86.     return(Data);
  87. }
  88.  
  89. VOID SAVE_DS ASM
  90. RendezvousLogoff(REG(a0) struct RendezvousData *Data)
  91. {
  92.     if(Data)
  93.     {
  94.         struct Node *Node,*Next;
  95.  
  96.         for(Node = Data->rd_UploadList.lh_Head ; Next = Node->ln_Succ ; Node = Next)
  97.             FreeVecPooled(Node);
  98.  
  99.         for(Node = Data->rd_DownloadList.lh_Head ; Next = Node->ln_Succ ; Node = Next)
  100.             FreeVecPooled(Node);
  101.  
  102.         for(Node = Data->rd_SentList.lh_Head ; Next = Node->ln_Succ ; Node = Next)
  103.             FreeVecPooled(Node);
  104.  
  105.         for(Node = Data->rd_ReceivedList.lh_Head ; Next = Node->ln_Succ ; Node = Next)
  106.             FreeVecPooled(Node);
  107.  
  108.         FreeVecPooled(Data);
  109.  
  110.         Signal((struct Task *)ThisProcess,SIG_HANDSHAKE);
  111.     }
  112. }
  113.  
  114. struct Node * SAVE_DS ASM
  115. RendezvousNewNode(REG(a0) STRPTR Name)
  116. {
  117.     if(Name)
  118.     {
  119.         LONG Len;
  120.  
  121.         if(Len = strlen(Name))
  122.         {
  123.             struct Node *Node;
  124.  
  125.             if(Node = (struct Node *)AllocVecPooled(sizeof(struct Node) + Len + 1,MEMF_ANY))
  126.             {
  127.                 memset(Node,0,sizeof(struct Node));
  128.  
  129.                 strcpy(Node->ln_Name = (STRPTR)(Node + 1),Name);
  130.  
  131.                 return(Node);
  132.             }
  133.         }
  134.     }
  135.  
  136.     return(NULL);
  137. }
  138.  
  139. VOID
  140. RendezvousSetup()
  141. {
  142.     InitSemaphore((struct SignalSemaphore *)&RendezvousSemaphore);
  143.  
  144. #ifdef USE_GLUE
  145.     RendezvousSemaphore.rs_Login    = RendezvousLoginGlue;
  146.     RendezvousSemaphore.rs_Logoff    = RendezvousLogoffGlue;
  147.     RendezvousSemaphore.rs_NewNode    = RendezvousNewNodeGlue;
  148. #else
  149.     RendezvousSemaphore.rs_Login    = RendezvousLogin;
  150.     RendezvousSemaphore.rs_Logoff    = RendezvousLogoff;
  151.     RendezvousSemaphore.rs_NewNode    = RendezvousNewNode;
  152. #endif    /* USE_GLUE */
  153. }
  154.  
  155. VOID
  156. AddRendezvousSemaphore(STRPTR Name)
  157. {
  158.     Forbid();
  159.  
  160.     RendezvousSemaphore.rs_Semaphore.ss_Link.ln_Name = Name;
  161.     RendezvousSemaphore.rs_Semaphore.ss_Link.ln_Pri  = -127;
  162.  
  163.     AddSemaphore((struct SignalSemaphore *)&RendezvousSemaphore);
  164.  
  165.     Permit();
  166. }
  167.  
  168. VOID
  169. RemoveRendezvousSemaphore()
  170. {
  171.     Forbid();
  172.  
  173.     if(RendezvousSemaphore.rs_Semaphore.ss_Link.ln_Name)
  174.         RemSemaphore((struct SignalSemaphore *)&RendezvousSemaphore);
  175.  
  176.     Permit();
  177. }
  178.